package com.maxlen.ware.controller;

import com.maxlen.common.utils.PageUtils;
import com.maxlen.common.utils.R;
import com.maxlen.ware.entity.PurchaseDetailEntity;
import com.maxlen.ware.entity.vo.PurchaseDetailPageParamsVO;
import com.maxlen.ware.service.PurchaseDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 采购单
 *
 * @author MaxLen
 * @email MaxLen@gmail.com
 * @date 2022-10-27 11:02:35
 */
@RestController
@RequestMapping("ware/purchasedetail")
public class PurchaseDetailController {
    @Autowired
    private PurchaseDetailService purchaseDetailService;

    /**
     * 列表
     */
    @PostMapping("/list")
    // @RequiresPermissions("ware:wareinfo:list")
    public R list(@RequestBody PurchaseDetailPageParamsVO params){
        PageUtils page = purchaseDetailService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    // @RequiresPermissions("ware:wareinfo:info")
    public R info(@PathVariable("id") Long id){
        PurchaseDetailEntity wareInfo = purchaseDetailService.getById(id);

        return R.ok().put("purchaseDetail", wareInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    // @RequiresPermissions("ware:wareinfo:save")
    public R save(@RequestBody PurchaseDetailEntity purchaseDetailEntity){
        purchaseDetailService.save(purchaseDetailEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    // @RequiresPermissions("ware:wareinfo:update")
    public R update(@RequestBody PurchaseDetailEntity purchaseDetailEntity){
        purchaseDetailService.updateById(purchaseDetailEntity);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    // @RequiresPermissions("ware:wareinfo:delete")
    public R delete(@RequestBody Long[] ids){
        purchaseDetailService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
